package com.lalameow.serverlogingate.network;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.lalameow.packet.enumtype.VailPlayerState;
import com.lalameow.packet.pojo.VaildPlayer;
import io.netty.channel.Channel;
import lombok.Getter;

import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * 创建人: 陈刚
 * 日期: 2018/5/11
 * 时间: 8:51
 * 功能：请进行修改
 */
public class ClientManager {
    public static ClientManager instanss=new ClientManager();
    @Getter
    private Cache<String,VailPlayerState> playerCache;
    @Getter
    private Cache<String,String> mcServerCache;


    private ClientManager() {
        playerCache= CacheBuilder.newBuilder()
                .concurrencyLevel(6)
                .expireAfterWrite(30, TimeUnit.SECONDS)
                .build();
        mcServerCache= CacheBuilder.newBuilder()
                .concurrencyLevel(2)
                .build();
    }
    public void  invaliPlayerCache(Channel channel){
//        Cache<String,VaildClient> playerCache= ClientManager.instanss.getPlayerCache();
//        String invalikey=null;
//        for (Map.Entry<String, VaildClient> stringVaildClientEntry : playerCache.asMap().entrySet()) {
//            if(stringVaildClientEntry.getValue().getChannel().id()==channel.id()){
//                invalikey=stringVaildClientEntry.getKey();
//                break;
//            }
//        }
//        if(invalikey!=null){
//            playerCache.invalidate(invalikey);
//        }
    }


}
